console.log(process.argv);
try {
  const fs = require("fs");
  const originName = process.argv[2];
  const outputName = process.argv[3];
  const actionName = process.argv[4];
  const file = fs.readFileSync("./" + originName, "utf-8");
  // fs.writeFileSync(
  //     './'+ new Date().getTime() + '.json',
  //     file.replaceAll(/\\/g,''),
  //     "utf-8"
  // );
  const jsonObject = file.split(/\n/);
  console.log(Object.prototype.toString.call(jsonObject));
  // // console.log(jsonObject.slice(0, 10));
  // let newJson = {};
  //
  let contents = jsonObject.map((row) => {
    const valueArr = row.split(",");
    const time = valueArr[0];
    valueArr.splice(0, 1);
    const value = valueArr.join(",");
    return {
      time,
      value,
    };
  });
  let obj = {
    contents,
  };
  fs.writeFileSync(
    "./" + outputName,
    actionName + "(" + JSON.stringify(obj) + ")",
    "utf-8"
  );
} catch (e) {
  console.log(e);
}
